//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <bulverde.h>
#include "mdma.h"

void init_dma(void)
{
	int i;
	for (i=0; i<CHANNEL_SIZE; i++)
	{
		if (DCSR(i)&DCSR_STOPINTR)
			dma_channels[i].inuse = 0;
		else
			dma_channels[i].inuse =1;
	}
}

void init_desc(void)
{
	read_desc = (struct dma_desc *)MMC_READ_DESC;
	write_desc = (struct dma_desc *)MMC_WRITE_DESC;
}
int request_dma(void)
{
	int i;
	for (i = 0; i < CHANNEL_SIZE; i++)
	{
		if (dma_channels[i].inuse==0)
			{
				dma_channels[i].inuse = 1;
				DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
				return i;
			}
	}
	return -1;
}
